package com.realestate.services;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.realestate.constants.ComTxManagerName;
import com.realestate.dao.UsersDao;
import com.realestate.model.BrtbUsers;

@Service
public class UsersServiceImpl implements UsersService{
	
	@SuppressWarnings("unused")
	private static final Logger LOGGER = Logger.getLogger(UsersServiceImpl.class);
	
	@Autowired
    private UsersDao userDao;

	@Override
	public BrtbUsers findUserByUsername(String username) {
		return userDao.findUserByUsername(username);
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void saveAvatar(String username, String avatar) {
		BrtbUsers user = findUserByUsername(username);
		user.setAvatar(avatar);
		userDao.flush();
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void createUser(BrtbUsers user) {
		userDao.persist(user);
		userDao.flush();
	}
}
